package com.pet.server.bo.common;

import java.io.File;
import java.util.Date;

import com.pet.framework.page.Page;
import com.pet.framework.util.Config;
import com.pet.framework.util.FileOperate;
import com.pet.server.dao.common.PetDao;
import com.pet.server.dao.common.ProductDao;
import com.pet.server.po.PetAdopt;
import com.pet.server.po.PetAdoptItem;
import com.pet.server.po.PetInfo;
import com.pet.server.po.PetMissing;
import com.pet.server.po.PetSay;
import com.pet.server.po.PetTimeLine;
import com.pet.server.po.ProductInfo;
import com.pet.system.constants.ATTSystem;
import com.pet.system.util.FolderManager;

public class PetService extends CommonService {
	
	public PetDao petDao;

	public PetDao getPetDao() {
		return petDao;
	}
	public void setPetDao(PetDao petDao) {
		this.petDao = petDao;
	}
	/**
	 * 保持宠物说
	 * @param petSay
	 * @param mp3File
	 * @param mp3FileName
	 */
	public void savePetInfo(PetSay petSay, File mp3File, String mp3FileName) {
		
		if(null!=petSay){
			if(null!=mp3File){
				String path = FolderManager.getSysUserFolder();
				String filename=FolderManager.getCurrentName(1000, mp3FileName);
				String resPath = FileOperate.uploadFile(mp3File, path, filename);
				petSay.setSource(Config.getValue("ftp.url")+resPath);
			}
			petSay.setCreateTime(new Date());
			petSay.setType("sound");
			petSay.setState(ATTSystem.LOGIC_TRUE);
			saveObject(petSay);
		}
		
		
	}
	/**
	 *  修改宠物说
	 * @param p
	 * @param petSay
	 * @param mp3File
	 * @param mp3FileName
	 */
	public void updatePetInfo(PetSay p, PetSay petSay, File mp3File,String mp3FileName) {
		if(null!=mp3File){
			String path = FolderManager.getSysUserFolder();
			String filename=FolderManager.getCurrentName(1000, mp3FileName);
			String resPath = FileOperate.uploadFile(mp3File, path, filename);
			p.setSource(Config.getValue("ftp.url")+resPath);
		}
		p.setTitle(petSay.getTitle());
		p.setPetCate(petSay.getPetCate());
		p.setSource(petSay.getSource());
		petSay.setType("sound");
		updateObject(p);
		
	}
	/**
	 * 查看宠物说
	 * @param petSay
	 * @param page
	 */
	public void searchPetInfo(PetSay petSay, Page page) {
		petDao.searchPet(petSay,page);
		
	}
	
	/**
	 * 查看遗失
	 * @param page
	 */
	public void searchPetMissing(PetMissing petMissing,Page page) {
		petDao.searchPetMissing(petMissing,page);
	}
	
	/**
	 * 宠物领养
	 * @param petAdopt
	 * @param page
	 */
	public void searchPetAdopt(PetAdopt petAdopt, Page page) {
		petDao.searchPetAdopt(petAdopt,page);
		
	}
	
	
	/**
	 * 申请宠物领养
	 * @param petAdoptItem
	 * @param page
	 */
	public void searchPetAdoptItem(PetAdoptItem petAdoptItem, Page page) {
		
		petDao.searchPetAdoptItem(petAdoptItem,page);
	}
	
	/**
	 * c宠物列表
	 * @param petInfo
	 * @param page
	 */
	public void searchPetInfo(PetInfo petInfo, Page page) {
		petDao.searchPetInfo(petInfo,page);
		
	}
	
	/**
	 * 宠物时间线
	 * @param petTimeLine
	 * @param page
	 */
	public void searchPetTimeLine(PetTimeLine petTimeLine, Page page) {
		petDao.searchPetTimeLine(petTimeLine,page);
		
	}
	/**
	 * 修改宠物领养 
	 * @param p
	 * @param petAdopt
	 */
	public void updatePetAdopt(PetAdopt p, PetAdopt petAdopt) {
		System.out.println("aaaaaaaaaaaaaaaa="+p.getAdoptId());
		p.setCity(petAdopt.getCity());
		p.setArea(petAdopt.getArea());
		p.setAge(petAdopt.getAge());
		p.setDescription(petAdopt.getDescription());
		p.setPhone(petAdopt.getPhone());
		p.setQq(petAdopt.getQq());
		p.setSex(petAdopt.getSex());
		p.setPetCate(petAdopt.getPetCate());
		updateObject(p);
		
	}

}
